package com.wj.crm.controller;

import com.wj.crm.base.BaseController;
import com.wj.crm.base.ResultInfo;
import com.wj.crm.query.CustomerServeQuery;
import com.wj.crm.service.CustomerServeService;
import com.wj.crm.utils.LoginUserUtil;
import com.wj.crm.vo.CustomerServe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author WangJin
 * @version 1.0
 * @date 2022/1/27 14:02
 */
@Controller
@RequestMapping("customer_serve")
public class CustomerServeController extends BaseController {
    @Autowired
    private CustomerServeService customerServeService;

    // 服务管理页面转发方法
    @RequestMapping("index/{type}")
    public String index(@PathVariable Integer type){
        if(type==1){
            return "customerServe/customer_serve";
        }else if(type==2){
            return "customerServe/customer_serve_assign";
        }else if(type==3){
            return "customerServe/customer_serve_proce";
        }else if(type==4){
            return "customerServe/customer_serve_feed_back";
        }else if(type==5){
            return "customerServe/customer_serve_archive";
        }else{
            return "";
        }
    }

    // 服务信息列表展示
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryCustomerServeByParams(Integer flag, HttpServletRequest request, CustomerServeQuery customerServeQuery){
        if(null !=flag && flag==1){
            customerServeQuery.setAssigner(LoginUserUtil.releaseUserIdFromCookie(request));
        }
        return customerServeService.queryByParamsForTable(customerServeQuery);
    }

    @RequestMapping("toAddCustomerServePage")
    public String toAddCustomerServePage(){

        return "customerServe/customer_serve_add";
    }



    /**
     * 创建服务
     * @param customerServe
     * @return com.wj.crm.base.ResultInfo
     */
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addCustomerServe(CustomerServe customerServe) {

        customerServeService.addCustomerServe(customerServe);
        return success("添加服务成功！");
    }


    /**
     * 服务更新
     *     1. 服务分配
     *     2. 服务处理
     *     3.服务反馈
     *
     * @param customerServe
     * @return com.wj.crm.base.ResultInfo
     */
    @PostMapping("update")
    @ResponseBody
    public ResultInfo updateCustomerServe(CustomerServe customerServe) {
        customerServeService.updateCustomerServe(customerServe);
        return success("服务更新成功！");
    }

    /**
     * 打开服务分配页面
     *
     * @param
     * @return java.lang.String
     */
    @RequestMapping("toCustomerServeAssignPage")
    public String toCustomerServeAssignPage(Integer id, Model model) {

        // 通过id查询服务记录，并设置到请求域中
        model.addAttribute("customerServe", customerServeService.selectByPrimaryKey(id));
        return "customerServe/customer_serve_assign_add";
    }

    /**
     * 打开服务处理页面
     *
     * @param
     * @return java.lang.String
     */
    @RequestMapping("toCustomerServeProcePage")
    public String toCustomerServeProcePage(Integer id, Model model) {

        // 通过id查询服务记录，并设置到请求域中
        model.addAttribute("customerServe", customerServeService.selectByPrimaryKey(id));
        return "customerServe/customer_serve_proce_add";
    }

    /**
     * 打开服务反馈页面
     *
     * @param
     * @return java.lang.String
     */
    @RequestMapping("toCustomerServeFeedBackPage")
    public String toCustomerServeFeedBackPage(Integer id, Model model) {

        // 通过id查询服务记录，并设置到请求域中
        model.addAttribute("customerServe", customerServeService.selectByPrimaryKey(id));
        return "customerServe/customer_serve_feed_back_add";
    }


    /**
     * 查询客户服务 （折线图）
     * @param
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping("countCustomerServe")
    @ResponseBody
    public Map<String, Object> countCustomerServe() {
        return customerServeService.countCustomerServe();
    }

    /**
     * 查询客户服务 （饼状图）
     * @param
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping("countCustomerServe02")
    @ResponseBody
    public Map<String, Object> countCustomerServe02() {
        return customerServeService.countCustomerServe02();
    }

}
